﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ServiceModel.Syndication;
using System.Xml;
using System.Diagnostics;

namespace ExcelRSS
{
    /// <summary>
    /// Interaction logic for RSSControl.xaml
    /// </summary>
    public partial class RSSControl : UserControl
    {
        private string FeedUrl = string.Empty;

        public RSSControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Loads the RSS Feed when done
        /// </summary>
        public string LoadFeed 
        {
            set
            {
                FeedUrl = value;

                LoadItems();
            }
        }

        /// <summary>
        /// Loads the RSS Feed
        /// </summary>
        private void LoadItems()
        {
            try
            {
                XmlReader reader = XmlReader.Create(FeedUrl);
                SyndicationFeed feed = SyndicationFeed.Load(reader);
                LstFeed.ItemsSource = feed.Items;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
